package ge.telasi.tasks.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * @author dimitri
 */
@Entity
@Table(name = "task_relations")
public class TaskRelation implements Serializable {
    private static final long serialVersionUID = -3858753182601810542L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TASK_RELATIONS_SEQ")
	@SequenceGenerator(name = "TASK_RELATIONS_SEQ", sequenceName = "TASK_RELATIONS_SEQ", allocationSize = 1)
    private Long id;
    @ManyToOne
    @JoinColumn(name = "parent_id")
    private Task parent;
    @ManyToOne
    @JoinColumn(name = "child_id")
    private Task child;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Task getParent() {
        return parent;
    }

    public void setParent(Task parent) {
        this.parent = parent;
    }

    public Task getChild() {
        return child;
    }

    public void setChild(Task child) {
        this.child = child;
    }

    @Override
    public boolean equals(Object obj) {
        if (id == null) {
            return false;
        }
        if (obj instanceof TaskRelation) {
            TaskRelation relation = (TaskRelation) obj;
            return id.equals(relation.getId());
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }


}
